package com.woniu.humanresource.service.impl;


import com.woniu.humanresource.dao.OrgStructureDao;
import com.woniu.humanresource.entity.OrgStructure;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.service.OrgStructureService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrgStructureServiceImpl implements OrgStructureService {

    @Resource
    OrgStructureDao orgStructureDao;


    @Override
    public void insertOrgStructure(OrgStructure orgStructure) {
        orgStructureDao.insertOrgStructure(orgStructure);
    }

    @Override
    public PageBean<OrgStructure> getAllOrgStructure(int pageIndex, int pageSize) {
        // 查询所有职位关系集合
        List<OrgStructure> allOrgStructure = orgStructureDao.selectAllOrgStructure(pageIndex, pageSize);
        // 封装为pageBean对象
        PageBean<OrgStructure> allOrgStructurepageBean = new PageBean<>();
        allOrgStructurepageBean.setBeanList(allOrgStructure);
        allOrgStructurepageBean.setPageIndex(pageIndex);
        allOrgStructurepageBean.setPageSize(pageSize);
        allOrgStructurepageBean.setBeginEnd();
        allOrgStructurepageBean.setTotalRecord(orgStructureDao.selectAllOrgStructurecounts());
        return allOrgStructurepageBean;
    }

    @Override
    public void updateOrgStructure(OrgStructure orgStructure, String orgname) {
        orgStructureDao.updateOrgStructure(orgStructure, orgname);
    }

    @Override
    public void deleteOrgStructureByOrgid(String orgid) {

    }

    @Override
    public List<OrgStructure> selectOrgStructureByOrgid(String orgid) {
        List<OrgStructure> orgStructureByOrgid = orgStructureDao.selectOrgStructureByOrgid(orgid);
        return orgStructureByOrgid;
    }

    @Override
    public void deleteApplyByOrgid(String orgid) {
        orgStructureDao.deleteApplyByPosition(orgid);
    }

    @Override
    public PageBean<OrgStructure> getOrgStructure(OrgStructure orgStructure, int pageIndex, int pageSize) {
        // 条件查询
        List<OrgStructure> orgStructureList = orgStructureDao.selectOrgStructure(orgStructure,pageIndex, pageSize);
        // 封装为pageBean对象
        PageBean<OrgStructure> orgStructurepageBean = new PageBean<>();
        orgStructurepageBean.setBeanList(orgStructureList);
        orgStructurepageBean.setPageIndex(pageIndex);
        orgStructurepageBean.setPageSize(pageSize);
        orgStructurepageBean.setBeginEnd();
        orgStructurepageBean.setTotalRecord(orgStructureDao.selectOrgStructureCounts(orgStructure));
        return orgStructurepageBean;
    }
}
